<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="../../common/import.jsp" %>
<%@ taglib uri="/WEB-INF/privilege" prefix="p"%>
<html>
  <head>
</head>
  <body scroll="no">
  <script type="text/javascript">
       jQuery.ajaxSetup({cache: false});
       $(function(){
    	   $("#dictTable").datagrid({
    		   //width: 'auto',
    		   nowrap: true,//文字在单元格内不换行
    		   triped: false,
    		   fitColumns: true,
    		   url: '${ctx}/sys/dict/list.do',
    		   columns: [[
    		             {field: 'ck', checkbox: true},
    		             {field: 'name', title: '字典名称', width: 80, align: 'center'},
    		             {field: 'code', title: '代码', width: 60, align: 'center'},
    		             {field: 'parentCode', title: '父代码', width: 60, align: 'center'},
    		             {field: 'val', title: '值', width: 60, align: 'center'},
    		             {field: 'orderIndex', title: '排序号', width: 30, align: 'center'}
    		            ]],
    		   pagination: true,
    		   rownumbers: true,
    		   pageSize: 20,
    		   pageList: pageList,
    		   queryParams: {}
    	   });
       });
       
       function reloadGrid(){
    	   $("#dictTable").datagrid("reload");
       }
       function getSelectedRows(){
    	   var rows = $('#dictTable').datagrid('getSelections');
    	   return rows;
       }
       function queryForm(){
    	   var params = $('#dictTable').datagrid('options').queryParams; //先取得 datagrid 的查询参数
    	   var fields =$('#queryForm').serializeArray(); //自动序列化表单元素为JSON对象
    	   $.each( fields, function(i, field){
    		   params[field.name] = field.value; //设置查询参数
           });   
    	   reloadGrid(); //设置好查询参数 reload 一下就可以了
       }
       function clearForm(){
    	   $('#queryForm').form('clear');
    	   queryForm();
       }
       
       function add(href){
    	   showWindow("添加数据字典", href, 600, 450);
    	   return false;
       }
       function edit(href){
    	   var node = getSelectedRows();
    	   if (node&&node.length==1){
    		   showWindow("修改数据字典", href + "?id="+node[0].id, 600, 450);
    		   
    	   }else{
    		   showAlertMsg();
    	   }
    	   return false;
       }
       function del(href){
    	   var rows = getSelectedRows();
    	   if (rows&&rows.length > 0){
    		   deleteConfirm(function(){
    			   var ps = "";
		           $.each(rows,function(i,n){
		        	   if(i==0) 
		        			ps += n.id;
		        		else
		        			ps += ","+n.id;
		        	});
		           $.blockUI();
    			   $.ajax({
		    			  url: href,
		    		      data: {ids: ps}, 
		    		      type: "POST",
		    		      success: function(data) {
		    		    	  $.unblockUI();
		    		        	if(data.success==true){
		    		        		showSuccessMsg();
		    		        		reloadGrid();
		    		        	}else{
		    		        		showFailAlert(data.msg);
		    		        	}
		    		      },
		    		      error: function(xhr) {
		    		    	  $.unblockUI();
		    		    	  showFailAlert2(xhr);
		    		      }
		    		  })
    		   });
    	   }else{
    		   showAlertMsg();
    	   }
    	   return false;
       }
       function view(href){
    	   var rows = getSelectedRows();
    	   if (rows&&rows.length==1){
    		   showWindow("查看数据字典", href+"?id="+rows[0].id, 600, 450);
    	   }else{
    		   showAlertMsg();
    	   }
    	   return false;
       }
    </script>
  <div class="easyui-layout" data-options="fit:true">
  <div region="north" style="overflow-y: hidden; overflow-x: hidden" border="false">
    <form id="queryForm" onSubmit="queryForm();return false;">
        <table width="99.5%" style="padding-left: 5px;">
	        <td width="55px">字典名称</td><td width="60px"><input id="name" type="text" name="name" value="" /></td>
		    <td width="85px"><a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" onclick="queryForm();">查询</a></td>
		    <td><a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" onclick="clearForm();">重置</a></td>
		</table>
    </form>
    <div class="btabs">
        <p:op code="sysDictAdd">
        	<a class="easyui-linkbutton" data-options="plain:true" href="${ctx}/sys/dict/toAdd.do" 
        	onclick="return add(this.href);"><span class="icon icon-add">&nbsp;</span>添加</a> 
        </p:op>
        <p:op code="sysDictEdit">
        	<a class="easyui-linkbutton" data-options="plain:true" href="${ctx}/sys/dict/toAdd.do" 
        	onclick="return edit(this.href);"><span class="icon icon-edit">&nbsp;</span>修改</a> 
        </p:op>
        <p:op code="sysDictDel">
        	<a class="easyui-linkbutton" data-options="plain:true" href="${ctx}/sys/dict/delete.do" 
        	onclick="return del(this.href);"><span class="icon icon-delete">&nbsp;</span>删除</a> 
        </p:op>
        <p:op code="sysDictView">
        	<a class="easyui-linkbutton" data-options="plain:true" href="${ctx}/sys/dict/toView.do" 
        	onclick="return view(this.href);"><span class="icon icon-view">&nbsp;</span>查看</a> 
        </p:op>
    </div>
    </div>
    <div region="center" style="padding: 1px;" border="false">
       <table id="dictTable" fit="true"></table>
    </div>
    </div>
  </body>
</html>
